import 'dart:collection';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_nft/api/API.dart';
import 'package:flutter_nft/provider/LoginProvider.dart';
import 'package:model_viewer/model_viewer.dart';
import 'package:provider/provider.dart';

class GlbIndex extends StatefulWidget {
  @override
  _GlbIndexState createState() => _GlbIndexState();
}

class _GlbIndexState extends State<GlbIndex> {

  late Map toMap = new HashMap();

  String maxurl = "";

  @override
  void initState() {
    _getnew();
    // TODO: implement initState
    super.initState();
  }

  void _getnew() async {
    try {
      print("get请求");
      var result = await Dio().get(API.reqUrl +
          "/get/threemax/detail/" +
          context.read<LoginProvider>().getProductDetailCode());
      print(result);
      // ProductNew? list = (result.data["dataObj"] as dynamic)
      //     .map((e) => ProductNew.fromMap((e as Map<String, dynamic>)))
      //     .toList();
      print("打印对象详情");
      setState(() {
        toMap = result.data['dataObj'];
      });
      print(result.data['dataObj']["threeMaxUrl"]);
      print('http://rec6p45ah.hn-bkt.clouddn.com/6363.glb');
      setState(() {
        maxurl = result.data['dataObj']["threeMaxUrl"];
      });
    } catch (e) {
      print("异常捕捉");
    }
  }

  @override
  Widget build(BuildContext context) {
    Object? teacherMap = ModalRoute.of(context)!.settings.arguments;
    print("传来的参数" + teacherMap.toString());

  //"3d展示(手势旋转,左右滑动)"
    return Scaffold(
      appBar: AppBar(
        title: Text(
          "3d展示(手势旋转,左右滑动)",
          style: TextStyle(fontSize: 16),
        ),
      ),
      body: Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        //decoration: BoxDecoration(borderRadius: BorderRadius.circular(150),color: Colors.black26,), 'http://rec6p45ah.hn-bkt.clouddn.com/6363.glb'
        child: ModelViewer(
          backgroundColor: Colors.teal[50],
          src: context.read<LoginProvider>().getProductMaxUrl().toString(),
          alt: "A 3D model of an table soccer",
          autoPlay: true,
          autoRotate: true,
          cameraControls: true,
        ),
      ),
    );
  }
}
